Aspects of the present invention relate to selecting an implementation for executing a query.
In certain client/user-server scenarios, a query may need to be invoked a multitude of times, for example, a user query to retrieve content for a page in a website. Such a query may return different results depending on a context in which the query is generated. Such a context may, for example, be: based on attributes of the user/client, their interests, role, permissions, etc. These are referred to sometimes as targeted or personalized results.
As each query execution event may generate different results, caching the query execution results may not always yield expected performance results, since the query may need to be re-executed frequently. So, for performance purposes, the focus is on the query itself. Ideally, it should be as optimized as possible for all the situations in which it may be executed. Depending on the circumstances, such as, for example, server load, data store size, user identity, role, access, etc. performance is expected to vary for query execution. This implies that a compromise may need to be made to obtain a single implementation that could be used for execution of a given query and whose corresponding performance record in this regard is such that it is considered to execute the query optimally/relatively better than other available implementations for all given circumstances.
Optimization of Extensible Markup language (XML) database queries may involve compiling an XML query into a query execution plan, which is then executed on an XML database. The compiled query may be optimized using some mechanisms, such as, for example, feeding the database statistics into the compiler so that it creates a query execution plan that best fits the database in its current state. Multiple versions of the query are subsequently generated. In this case, it is likely that the database statistics may not always be updated/current at the compile time of the XML query into a query execution plan, and thus, such compilation may be done based on stale statistics. Furthermore, since the input parameters are unavailable to the compiler at compile time, an optimized query execution plan is unlikely to be generated. The compiler may be configured to generate multiple execution plans for executing the same query. Which of the execution plans is used for query execution by the database management system is determined by dedicated code generated by the compiler for analyzing the input parameters and current database state. Such an analysis is then used for determining the optimum query execution plan to use.
Accordingly, it is a challenge to provide for query execution that may be performed with increased accuracy and conservation of processing resources.